package com.cykj.pos.util;

import com.cykj.pos.domain.posone.PosOneMerchantInfo;
import com.cykj.pos.profit.dto.MerchantInfoDTO;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ListUtils {
    public static <T> String toString(List<T> list, char separator) {
        return StringUtils.join(list.toArray(),separator);
    }
    /*public static void main(String[] args){
        List<Long> ids = new ArrayList<>();
        ids.add(1L);ids.add(2L);ids.add(20L);ids.add(11L);
        System.out.println(ListUtils.toString(ids,','));
    }*/
    // 方式1: 降序排列
   public static List<MerchantInfoDTO> searchDes(List<MerchantInfoDTO> logsList){
       Collections.sort(logsList, new Comparator<MerchantInfoDTO>() {
          @Override
          public int compare(MerchantInfoDTO o1, MerchantInfoDTO o2) {
                             if ((o1.getTransAmount().compareTo(o2.getTransAmount())==1)){
                                     return -1;
                                 }
                             if ((o1.getTransAmount().compareTo(o2.getTransAmount())==1)){
                                     return 0;
                                 }
                             return 1;
                         }
      });
      return logsList;
   }

    // 方式2: 升序排列
   public static List<MerchantInfoDTO> searchAsc(List<MerchantInfoDTO> logsList){
             Collections.sort(logsList, new Comparator<MerchantInfoDTO>() {
          @Override
          public int compare(MerchantInfoDTO o1, MerchantInfoDTO o2) {
                             if ((o1.getTransAmount().compareTo(o2.getTransAmount())==1)){
                                     return 1;
                                 }
                             if (o1.getTransAmount().compareTo(o2.getTransAmount())==1){
                                     return 0;
                                 }
                             return -1;
                         }
      });
      return logsList;
   }

    // 方式1: 降序排列
    public static List<PosOneMerchantInfo> searchPosOneDes(List<PosOneMerchantInfo> logsList){
        Collections.sort(logsList, new Comparator<PosOneMerchantInfo>() {
            @Override
            public int compare(PosOneMerchantInfo o1, PosOneMerchantInfo o2) {
                if ((o1.getTransAmount().compareTo(o2.getTransAmount())==1)){
                    return 1;
                }
                if ((o1.getTransAmount().compareTo(o2.getTransAmount())==-1)){
                    return -1;
                }
                return 0;
            }
        });
        return logsList;
    }

    // 方式2: 升序排列
    public static List<PosOneMerchantInfo> searchPosOneAsc(List<PosOneMerchantInfo> logsList){
        Collections.sort(logsList, new Comparator<PosOneMerchantInfo>() {
            @Override
            public int compare(PosOneMerchantInfo o1, PosOneMerchantInfo o2) {
                if ((o1.getTransAmount().compareTo(o2.getTransAmount())==1)){
                    return 1;
                }
                if (o1.getTransAmount().compareTo(o2.getTransAmount())==1){
                    return 0;
                }
                return -1;
            }
        });
        return logsList;
    }
}
